<?php 
require ('../businessObjects/enterprise.php');
require ('../businessObjects/employee.php');
require ('../businessObjects/accountableTransaction.php');

switch ($_GET['opt']){
	case 'ENT': 
		$enterprise = new enterprise();		
		$enterprise->getEnterprise('');							
		$items = array();
		while($row = mysqli_fetch_array($enterprise->resultSet()))
		{
			 $option = array("id" => $row['enterpriseID'], "value" => htmlentities($row['enterpriseName']));
            $items[] = $option;
		}
		$data = json_encode($items);     
		$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data; 
		echo($response);   
	break; 
	case 'EMP':
		$enterpriseID = !empty($_GET['id']) ?intval($_GET['id']):0;
		$employee = new employee();		
		$employee->getEmployee($enterpriseID);							
		$items = array();
		while($row = mysqli_fetch_array($employee->resultSet()))
		{
			$option = array("id" => $row['employeeID'], "value" => htmlentities($row['LastName'].','.$row['FirstName']));
            $items[] = $option;
		}
		$data = json_encode($items);     
		$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data; 
		echo($response);   
	break;
	case 'PEC':
		$enterpriseID = !empty($_GET['id']) ?intval($_GET['id']):0;
		$expense = new expense();		
		$expense->getExpenseCategory($enterpriseID);
		$items = array();
		while($row = mysqli_fetch_array($expense->resultSet()))
		{
			$option = array("id" => $row['categoryId'], "value" => htmlentities($row['categoryName']));
            $items[] = $option;
		}
		$data = json_encode($items);     
		$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data; 
		echo($response);   
	break;
	case 'CEC':
		$categoryID = !empty($_GET['id']) ?intval($_GET['id']):0;
		$expense = new expense();		
		$expense->getExpenseByParentCategory($categoryID);							
		$items = array();
		while($row = mysqli_fetch_array($expense->resultSet()))
		{
			$option = array("id" => $row['categoryId'], "value" => htmlentities($row['categoryName']));
            $items[] = $option;
		}
		$data = json_encode($items);     
		$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data; 
		echo($response);   
	break;
	case 'PRC':
		$enterpriseID = !empty($_GET['id']) ?intval($_GET['id']):0;
		$reimbursement = new reimbursement();		
		$reimbursement->getReimbursementCategory($enterpriseID);							
		$items = array();
		while($row = mysqli_fetch_array($reimbursement->resultSet()))
		{
			$option = array("id" => $row['categoryId'], "value" => htmlentities($row['categoryName']));
            $items[] = $option;
		}
		$data = json_encode($items);     
		$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data; 
		echo($response);   
	break;
	case 'CRC':
		$categoryID = !empty($_GET['id']) ?intval($_GET['id']):0;
		$reimbursement = new reimbursement();		
		$reimbursement->getReimbursementByParentCategory($categoryID);							
		$items = array();
		while($row = mysqli_fetch_array($reimbursement->resultSet()))
		{
			$option = array("id" => $row['categoryId'], "value" => htmlentities($row['categoryName']));
            $items[] = $option;
		}
		$data = json_encode($items);     
		$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data; 
		echo($response);   
	break;
	case 'finDashboard':
		$year = $_GET['year'];
		$month = $_GET['month'];
		$dataMember = $_GET['datamember'];
		switch ($dataMember) {
			case 'income': $obj = new income();break;
			case 'expense':$obj = new expense();break;
			case 'reimbursement': $obj = new reimbursement();break;
		}

		$obj->dataset_PerEnterprisePerCategoryPerDate($year,$month);
		$items = array();
		while($row = mysqli_fetch_array($obj->resultSet()))
		{
			$option = array("enterpriseName" => $row['enterpriseName'], 
							"categoryName" => htmlentities($row['categoryName']),
							"total_GTQ" => htmlentities($row['total_GTQ'])
							);
            $items[] = $option;
		}
		$data = json_encode($items);     
		$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data; 
		echo($response);   
	break;
	
	case 'annualReports_1':		
		$year = $_GET['year'];		
		$dataMember = $_GET['datamember'];
		switch ($dataMember) {
			case 'income': $obj = new income();break;
			case 'expense':$obj = new expense();break;
			case 'reimbursement': $obj = new reimbursement();break;
		}
		$obj->dataset_PerEnterprisePerCategoryPerYear($year);
		$items = array();
		while($row = mysqli_fetch_array($obj->resultSet()))
		{
			$option = array("enterpriseName" => $row['enterpriseName'], 
							"parent_category" => htmlentities($row['parent_category']),
							"categoryName" => htmlentities($row['categoryName']),
							"January" => htmlentities($row['January']),
							"February" => htmlentities($row['February']),
							"March" => htmlentities($row['March']),
							"April" => htmlentities($row['April']),
							"May" => htmlentities($row['May']),
							"June" => htmlentities($row['June']),
							"July" => htmlentities($row['July']),
							"August" => htmlentities($row['August']),
							"September" => htmlentities($row['September']),
							"October" => htmlentities($row['October']),
							"November" => htmlentities($row['November']),
							"December" => htmlentities($row['December'])							
							);
            $items[] = $option;
		}
		$data = json_encode($items);     
		$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data; 
		echo($response);   
	break;
	case 'annualReports_2':		
		$year = $_GET['year'];		
		$dataMember = $_GET['datamember'];
		switch ($dataMember) {			
			case 'expense':$obj = new expense();break;
			case 'reimbursement': $obj = new reimbursement();break;
		}	
		$obj->dataset_PerEnterprisePerEmployeePerCategoryPerYear($year);
		$items = array();
		while($row = mysqli_fetch_array($obj->resultSet()))
		{
			$option = array("enterpriseName" => $row['enterpriseName'], 
							"employeeName" => htmlentities($row['employeeName']),
							"parent_category" => htmlentities($row['parent_category']),							
							"categoryName" => htmlentities($row['categoryName']),
							"January" => htmlentities($row['January']),
							"February" => htmlentities($row['February']),
							"March" => htmlentities($row['March']),
							"April" => htmlentities($row['April']),
							"May" => htmlentities($row['May']),
							"June" => htmlentities($row['June']),
							"July" => htmlentities($row['July']),
							"August" => htmlentities($row['August']),
							"September" => htmlentities($row['September']),
							"October" => htmlentities($row['October']),
							"November" => htmlentities($row['November']),
							"December" => htmlentities($row['December'])							
							);
            $items[] = $option;
		}
		$data = json_encode($items);     
		$response = isset($_GET['callback'])?$_GET['callback']."(".$data.")":$data; 
		echo($response);   
	break;
	
}
	
?>